<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core" xmlns:c="http://java.sun.com/jsp/jstl/core" xmlns:p="http://primefaces.org/ui">


<ui:composition template="/WEB-INF/templates/maintemplate.xhtml">
	<ui:define name="globalMesages">
		<p:messages id="globalMessageId" globalOnly="false" showDetail="false" autoUpdate="true" closable="true"></p:messages>
	</ui:define>
	<ui:define name="content">
		<h:form id="listForm">
			<p:dataTable id="affiliateTable" value="#{affiliateBackingBean.allAffiliateList}" var="affiliate1" paginator="true" rows="20"
				paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink}  {PageLinks}  {CurrentPageReport} {NextPageLink} {LastPageLink}"
				paginatorPosition="both" tableStyleClass="noBorderTable" lazy="false" editable="true">
				<p:ajax event="rowEdit" listener="#{affiliateBackingBean.onEdit}" update="@this" />
				<p:column headerText="#{msgs.Name}">
					<p:cellEditor>
						<f:facet name="output">
							<h:outputText value="#{affiliate1.name}" />
						</f:facet>
						<f:facet name="input">
							<p:inputText value="#{affiliate1.name}" />
						</f:facet>
					</p:cellEditor>
				</p:column>
				<p:column headerText="#{msgs.PublishId}">
					<p:cellEditor>
						<f:facet name="output">
							<h:outputText value="#{affiliate1.publishId}" />
						</f:facet>
						<f:facet name="input">
							<p:inputText value="#{affiliate1.publishId}" />
						</f:facet>
					</p:cellEditor>
				</p:column>
				<p:column headerText="#{msgs.Token}">
					<p:cellEditor>
						<f:facet name="output">
							<h:outputText value="#{affiliate1.token}" />
						</f:facet>
						<f:facet name="input">
							<p:inputText value="#{affiliate1.token}" />
						</f:facet>
					</p:cellEditor>
				</p:column>
				<p:column headerText="#{msgs.URLPattern}">
					<p:cellEditor>
						<f:facet name="output">
							<h:outputText value="#{affiliate1.urlPattern}" />
						</f:facet>
						<f:facet name="input">
							<p:inputText value="#{affiliate1.urlPattern}" />
						</f:facet>
					</p:cellEditor>
				</p:column>
				<p:column headerText="#{msgs.AffiliateReportURL}">
					<p:cellEditor>
						<f:facet name="output">
							<h:outputText value="#{affiliate1.transactionReportWSEndPoint}" />
						</f:facet>
						<f:facet name="input">
							<p:inputText value="#{affiliate1.transactionReportWSEndPoint}" />
						</f:facet>
					</p:cellEditor>
				</p:column>
				<p:column>
					<p:rowEditor />
				</p:column>
				<p:column headerText="#{msgs.action}" rendered="#{login.userInSysadmin}">
					<h:panelGroup>
						<p:commandButton value="#{msgs.deleteButton}" actionListener="#{affiliateBackingBean.setAffiliate(affiliate1)}" update=":delConfgDiaForm"
							process="@form" oncomplete="DelConfgDia.show()" styleClass="commandButtonOrLink" onerror="HandleAjaxError(xhr, satus, exception)">
						</p:commandButton>
						<p:commandButton value="popDeals" actionListener="#{affiliateBackingBean.populateAffiliateDeal(affiliate1)}" update="@form" process="@form"
							styleClass="commandButtonOrLink" disabled="#{empty affiliate1.promLinkWSEndPoint}">
						</p:commandButton>
						<p:commandButton value="getTranReport" actionListener="#{affiliateBackingBean.getDailyTransactionReport(affiliate1)}" update="@none"
							process="@form" styleClass="commandButtonOrLink" disabled="#{empty affiliate1.transactionReportWSEndPoint}">
						</p:commandButton>

					</h:panelGroup>
				</p:column>
			</p:dataTable>
		</h:form>

		<div style="display: inline; float: left; margin-top: 10px;">
			<p:commandButton value="#{msgs.AddAffiliate}" oncomplete="PF('addAffiliate').show();" rendered="#{login.userInSysadmin}">
			</p:commandButton>
		</div>

		<p:dialog id="confirmation" widgetVar="DelConfgDia" header="#{msgs.Delete_Dialog_Header} " modal="true" height="150" width="500">
			<h:form id="delConfgDiaForm">
				<h:panelGrid id="selectupdate">
					<h:outputFormat value="#{msgs.Affiliate_Delete }">
						<f:param value="#{affiliateBackingBean.affiliate.name}">
						</f:param>
					</h:outputFormat>
					<!-- create some space between the label and the button -->
					<br></br>
					<br></br>
					<h:panelGrid columns="2">
						<p:commandButton id="confirm" value="#{msgs.Delete_Dialog_Yes}" update=":listForm" process="@this" oncomplete="DelConfgDia.hide()"
							actionListener="#{affiliateBackingBean.deleteAffiliate()}" />
						<p:commandButton id="decline" value="#{msgs.Delete_Dialog_No}" onclick="DelConfgDia.hide()" type="button" />
					</h:panelGrid>

				</h:panelGrid>
			</h:form>
		</p:dialog>
		<p:dialog id="addAffiliate" widgetVar="addAffiliate" header="#{msgs.AddAffiliate}" modal="true" height="250" width="600">
			<h:form id="addAffiliateForm">
				<h:panelGrid columns="3" columnClasses="th">
					<h:outputLabel value="#{msgs.Name}"></h:outputLabel>
					<h:inputText id="nameInAdd" value="#{affiliateBackingBean.affiliate.name}">
					</h:inputText>
					<h:message for="nameInAdd"></h:message>
					<h:outputLabel value="#{msgs.PublishId}"></h:outputLabel>
					<h:inputText id="publishIdInAdd" value="#{affiliateBackingBean.affiliate.publishId}" />
					<h:message for="publishIdInAdd"></h:message>
					<h:outputLabel value="#{msgs.Token}"></h:outputLabel>
					<h:inputText value="#{affiliateBackingBean.affiliate.token}" />
					<h:outputLabel></h:outputLabel>
					<h:outputLabel value="#{msgs.URLPattern}"></h:outputLabel>
					<h:inputText value="#{affiliateBackingBean.affiliate.urlPattern}" />
					<h:outputLabel></h:outputLabel>
					<h:panelGroup>
						<p:commandButton value="#{msgs.submit}" action="#{affiliateBackingBean.createAffiliate()}" process="@form" update="@form :listForm"
							oncomplete="handleComplete(xhr, status, args)">
						</p:commandButton>
						<p:commandButton id="cancel" value="#{msgs.CANCEL}" onclick="PF('addAffiliate').hide()" type="button" />
					</h:panelGroup>
				</h:panelGrid>
			</h:form>
		</p:dialog>
	</ui:define>
</ui:composition>

</html>